<template>
  <div class="my-goods-item">
    <div class="left">
      <div class="custom-control custom-checkbox">
        <!-- 双向绑定check 点击时返回checked状态给父组件-->
        <!-- <input type="checkbox" class="custom-control-input" id="input" v-model="check"> -->
        <input type="checkbox" class="custom-control-input" id="input" :checked="value.goods_state" @click="$emit('input', $event.target.checked)">
        <label class="custom-control-label" for="input">
          <!-- 填入value -->
          <img :src="value.goods_img" alt="">
        </label>
      </div>
    </div>
    <div class="right">
      <!-- 填充商品名 -->
      <div class="top">{{ value.goods_name }}</div>
      <div class="bottom">
        <!-- 计算价格并保留两位小数 -->
        <span class="price">¥ {{ (value.goods_price * value.goods_count).toFixed(2) }}</span>
        <span>
            <!-- 设置插槽名为count -->
            <slot name="count"></slot>
        </span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  // 接收信息
  props:{
    value:{
      type: Object,
      required: true
    }
  },
  // data(){
  //   return{
  //     // 零时存放
  //     check: false
  //   }
  // },
  created(){
    // 调用模块立马运行吧value的goods_state赋值给check
    this.check = this.value.goods_state
  },
  // watch:{
  //   // 监听check如有变化传回给父组件
  //   check:{
  //     handler(){
  //       this.$emit('input', this.check)
  //     }
  //   }
  // },
}
</script>

<style lang="less" scoped>
.my-goods-item {
  display: flex;
  padding: 10px;
  border-bottom: 1px solid #ccc;
  .left {
    img {
      width: 120px;
      height: 120px;
      margin-right: 8px;
      border-radius: 10px;
    }
    .custom-control-label::before,
    .custom-control-label::after {
      top: 50px;
    }
  }
  .right {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    .top{
        font-size: 14px;
        font-weight: 700;
    }
    .bottom {
      display: flex;
      justify-content: space-between;
      padding: 5px 0;
      align-items: center;
      .price {
        color: red;
        font-weight: bold;
      }
    }
  }
}

</style>